package com.example.demos.web.controller;

import com.example.demos.dto.*;
import com.example.demos.service.EmpService;
import com.example.demos.service.StoreService;
import com.example.demos.util.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpSession;

@RestController
@RequestMapping("/v2/")
public class StoreDetailController {
    @Autowired
    private StoreService storeService;

    @Autowired
    private EmpService empService;

    @GetMapping("storedetail/storeList")
    public Result<?> storeList() {
        return Result.ok(storeService.getStoreList());
    }


    @GetMapping("storedetail/goodsList")
    public Result<?> goodsList() {
        return Result.ok(storeService.getGoodsList());
    }


    @GetMapping("storedetail")
    public Result<?> storeDetail(StoreDetailQueryDTO storeDetailQueryDTO) {
        return Result.ok(storeService.getStoreDetailList(storeDetailQueryDTO));
    }

    @GetMapping("storeoper/emp_list")
    public Result<?> getEmpList() {
        return Result.ok(empService.selectForList());
    }


    @GetMapping("storeoper/store_list")
    public Result<?> getStoreList() {
        return Result.ok(storeService.getStoreList());
    }


    @GetMapping("storeoper/goods_list")
    public Result<?> getGoodsList() {
        return Result.ok(storeService.getGoodsList());
    }


    @GetMapping("storeoper")
    public Result<?> storeOperation(ChangeListQueryDTO changeListQueryDTO) {
        return Result.ok(storeService.getStoreChangeRecords(changeListQueryDTO));
    }


    @GetMapping("inventory/goodsList")
    public Result<?> getInventoryGoodsList() {
        return Result.ok(storeService.getGoodsList());
    }


    @GetMapping("inventory/storeList")
    public Result<?> getInventoryStoreList() {
        return Result.ok(storeService.getStoreList());
    }


    @PostMapping("inventory/add")
    public Result<?> addInventory(InventoryAddParamsDTO inventoryAddParamsDTO, HttpSession httpSession) {
        return storeService.addInventory(inventoryAddParamsDTO, httpSession) ? Result.ok("新增成功") : Result.err(400, "字段不完整或数量不合法");
    }

    @GetMapping("inventory/listByPage")
    public Result<?> listByPage(InventoryQueryDTO inventoryQueryDTO) {
        return Result.ok(storeService.getInventoryListByPage(inventoryQueryDTO));

    }

    @GetMapping("inventory/selectone")
    public Result<?> listByPage(Integer id) {
        return Result.ok(storeService.getInventoryById(id));
    }

    @PostMapping("inventory/update")
    public Result<?> updateInventory(InventoryEditParamsDTO editParamsDTO,HttpSession httpSession) {
        int i = storeService.editInventoryById(editParamsDTO,httpSession);
        return i == 1 ? Result.ok("审核/编辑成功") : Result.err(400, "审核/编辑失败");
    }

    @DeleteMapping("inventory")
    public Result<?> deleteInventory(Integer id) {
        int i = storeService.deleteInventoryById(id);
        return i == 1 ? Result.ok("删除成功") : Result.err(400, "删除失败");
    }

    @GetMapping("storealert")
    public Result<?> getStoreAlertInfo(Integer page, Integer rows) {
        return Result.ok(storeService.getStoreAlertInfo(page, rows));
    }


    @GetMapping("sendMsg")
    public Result<?> sendMsg(String tel) {
        return storeService.sendMsg("13009320186") ? Result.ok("发送成功") : Result.err(400, "短信发送错误");
    }


    @GetMapping("getStoreManager")
    public Result<?> getStoreManager() {
        return Result.ok(storeService.getStoreManager());
    }

}
